<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>店铺昵称</title>

    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/yzl.css"/>

    <style>
        .username-warn {
            font-size: 12px;
            margin: 20px 15px;
        }

        .username-warn > span {
            background-size: 22px 22px;
            background-position: left center;
            background-repeat: no-repeat;
            padding-left: 22px;
        }

        .username-warn > span.big {
            background-image: url(../../image/big/username_icon_warn.png);
        }

        .username-warn > span.small {
            background-image: url(../../image/small/username_icon_warn.png);
        }
    </style>

</head>
<body>
<div id="blank" class="header">
    <div v-back.tapmode class="back"></div>
    <span class="title">店铺昵称</span>
</div>
<div id="app" class="main-container">
    <input id="input" v-model="shopname" type="text" placeholder="请输入您的店铺昵称"
           style="font-size:14px;margin-top:10px;padding-left:15px;width:100%;height:46px;line-height:normal;background-color:white;outline: none;">
    <a class="btn-commit"  v-myclick="updshopname" >提交</a>
</div>
</body>
<script src="../../script/api.js"></script>
<script src="../../script/vue.js"></script>
<script src="../../script/app.js"></script>
<script src="../../script/common.js"></script>
<script src="../../script/url.js"></script>
<script>
    apiready = function () {
        setBSImg();
        new Vue({
            el: '#blank'
        });
        var data = {member_id: getPrefs('member_id')};
        var callback = function (ret) {
            shopinfo = ret.content;
            shopname = shopinfo.shopname;
            initApp();
            api.parseTapmode();
        };
        pinet.post(URL.getShopInfo, data, callback);
        api.parseTapmode();
        addListeners();
    };

    function initApp() {
        var vm = new Vue({
            el: '#app',
            data: {
                shopname:shopname,
                BSImg: {
                    big: Vue.BSImg == 'big',
                    small: Vue.BSImg == 'small'
                }
            },
            watch:{
                shopname:function (n, o) {
                    this.nameByte = n.replace(/[^\x00-\xff]/g,"xx").length;
                    if(this.nameByte > 12){
                        this.shopname = o;
                    }
                }
            },
            methods: {
                updshopname: function () {
                  if(!this.shopname.trim()){
                        alert('修改失败:昵称为空');
                        return;
                    }
                    showProgress();
                    var data = {
                        member_id: getPrefs('member_id'),
                        shopname: this.shopname
                    };
                    var callback = function (ret) {
                        api.sendEvent({
                            name: 'updshop',
                            extra: {
                                shopname: vm.shopname,
                            }
                        });
                        api.closeWin();
                    };
                    pinet.post(URL.updShopInfo, data, callback);
                },
            },
        });
    }
    function addListeners() {
        api.addEventListener({
            name: 'viewappear'
        }, function () {
            onPageStart();
        });

        api.addEventListener({
            name: 'viewdisappear'
        }, function (ret, err) {
            onPageEnd();
        });

        api.addEventListener({
            name: 'keyback'
        }, function (ret, err) {
            onPageEnd();
            api.closeWin();
        });
    }
</script>
</html>
